package com.hunttown.mes.convert;

import com.google.common.collect.Lists;
import com.hunttown.mes.common.utils.BeanUtils;
import com.hunttown.mes.domain.AnalysisNoticeCatalog;
import com.hunttown.mes.rpc.domain.AnalysisNoticeCatalogDTO;
import com.hunttown.mes.rpc.exception.ConvertException;
import com.hunttown.mes.rpc.domain.enums.ErrorCode;
import org.apache.commons.collections.CollectionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Collections;
import java.util.List;

/**
 * created by wangjunfu on 2018-11-26 15:06:26
 */
public class AnalysisNoticeCatalogConverts {

    private static Logger LOG = LoggerFactory.getLogger(AnalysisNoticeCatalogConverts.class);

    public static List<AnalysisNoticeCatalogDTO> convert(List<AnalysisNoticeCatalog> analysisNoticeCatalogList) {
        if (CollectionUtils.isEmpty(analysisNoticeCatalogList)) {
            return Collections.EMPTY_LIST;
        }

        List<AnalysisNoticeCatalogDTO> analysisNoticeCatalogListResult = Lists.newArrayList();
        for (AnalysisNoticeCatalog analysisNoticeCatalog : analysisNoticeCatalogList) {
            analysisNoticeCatalogListResult.add(convert(analysisNoticeCatalog));
        }
        return analysisNoticeCatalogListResult;
    }

    public static AnalysisNoticeCatalogDTO convert(AnalysisNoticeCatalog analysisNoticeCatalog) {
        try {
            return BeanUtils.copy(analysisNoticeCatalog, AnalysisNoticeCatalogDTO.class);
        } catch (Exception e) {
            LOG.error("AnalysisNoticeCatalog到AnalysisNoticeCatalogDTO转换失败!", e);
            throw new ConvertException(ErrorCode.CONVERT_ERROR, "AnalysisNoticeCatalog到AnalysisNoticeCatalogDTO转换失败", e);
        }
    }

    public static AnalysisNoticeCatalog convert(AnalysisNoticeCatalogDTO analysisNoticeCatalogDTO) {
        try {
            return BeanUtils.copy(analysisNoticeCatalogDTO, AnalysisNoticeCatalog.class);
        } catch (Exception e) {
            LOG.error("AnalysisNoticeCatalogDTO到AnalysisNoticeCatalog转换失败!", e);
            throw new ConvertException(ErrorCode.CONVERT_ERROR, "AnalysisNoticeCatalogDTO到AnalysisNoticeCatalog转换失败", e);
        }
    }
}